import { Serialize } from '@/common/decorator/serialize.decorator';
import { IdsDto } from '@/common/dto/ids.dto';
import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Post,
  Put,
  Query,
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { DeptsService } from './depts.service';
import { CreateDeptDto } from './dto/create-dept.dto';
import { UpdateDeptDto } from './dto/update-dept.dto';
import { SysDept } from './entities/dept.entity';
import { SearchDeptDto } from './dto/search-dept.dto';

@ApiTags('部门管理')
@Controller('dept')
export class DeptsController {
  constructor(private readonly deptsService: DeptsService) {}

  @Post()
  @ApiOperation({ summary: '创建部门' })
  @Serialize(SysDept)
  create(@Body() data: CreateDeptDto) {
    return this.deptsService.create(data);
  }

  @Get()
  @Serialize(SysDept)
  findAll(@Query() query: SearchDeptDto) {
    return this.deptsService.findAll(query);
  }

  @Get(':id/form')
  @ApiOperation({ summary: '根据ID查询' })
  @Serialize(SysDept)
  findOne(@Param('id', ParseIntPipe) id: number) {
    return this.deptsService.findOne(id);
  }

  @Put(':id')
  @ApiOperation({ summary: '修改部门' })
  update(@Param('id', ParseIntPipe) id: string, @Body() data: UpdateDeptDto) {
    return this.deptsService.update(+id, data);
  }

  @Delete(':ids')
  @ApiOperation({ summary: '删除部门' })
  remove(@Param() ids: IdsDto) {
    return this.deptsService.remove(ids);
  }

  @Get('options')
  // @Serialize(SysDept)
  findTree() {
    return this.deptsService.findTree();
  }
}
